********Table E.1 - Mexico********

*Load data
cd "$reploc/data/created_data"
use mex_full, clear

*Create primary and full sample indicators
sort pid_link mxfls
foreach var of varlist rbuc_nga rbuc grbrprovAvg_lam0co3 grbrprovSD_lam0co3 inflation{
gen `var'dif=`var'-`var'[_n-1] if mxfls==3 & pid_link==pid_link[_n-1]
} 

gen coh_prov_clust=yearprov

gen primarysample1=0
replace primarysample1=1 if rbuc_ngadif!=. & grbrprovAvg_lam0co3dif!=. & grbrprovSD_lam0co3dif!=. & inflationdif!=. &  birthyr>=1925 & coh_prov_clust!=.

egen primarysample=total(primarysample1), by(pid_link)

gen eithrisk=0
replace eithrisk=1 if rbucdif!=. 

egen fullsample=total(eithrisk), by(pid_link)

keep woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 rbuc rbuc_nga mxfls panel primarysample fullsample entrep evermig income_ia assets_ia savingnettotal_ia aggexpcons_ia smoke eithrisk homiciderate

label var woman "Woman"
label var imp_age "Age"
label define mxflslab 2 "2" 3 "3", modify
label values mxfls  mxflslab
label define pan 1 "Panel" 0 "Non-panel", modify
label values mxfls  mxflslab
label values panel pan

count if primarysample==1
count if fullsample==1
 
cd "$reploc/results"
outreg2 using TableE1_Mexico.tex if primarysample==1, sum(log) replace label eqkeep(N mean) keep(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia assets_ia savingnettotal_ia) sortvar(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia assets_ia savingnettotal_ia)

outreg2 using TableE1_Mexico.tex if primarysample==1, sum(log) append label eqkeep(N sd) keep(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia assets_ia savingnettotal_ia) sortvar(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig iincome_ia assets_ia savingnettotal_ia)

outreg2 using TableE1_Mexico.tex if fullsample==1, sum(log) append label sum eqkeep(N mean) keep(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia assets_ia savingnettotal_ia) sortvar(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia assets_ia savingnettotal_ia)

outreg2 using TableE1_Mexico.tex if fullsample==1, sum(log) append label sum eqkeep(N sd) keep(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia assets_ia savingnettotal_ia) sortvar(rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia assets_ia savingnettotal_ia)

**T-test differences
foreach var of varlist rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia assets_ia savingnettotal_ia  {
gen `var'ps=`var' if primarysample==1
}

local nams rbuc woman imp_age married hhsize Eddum1 Eddum2 Eddum3 Eddum4 evermig income_ia assets_ia savingnettotal_ia

foreach nam in `nams'  {

ttest `nam'==`nam'ps, unpaired unequal
}
